<?php
namespace Home\Controller;
use Think\Controller;
class ProductController extends Controller {
    public function product(){
        $nav=M('nav')->select();
        $this->assign('nav',$nav);
		$cat_pro=M('cat_pro')->select();
		$this->assign('cat_pro',$cat_pro);

		if(I('post.pro_name')){
			$pro_name=I('post.pro_name');
			$limit=6;
			$count=M('product')
					->where("pro_name like '%$pro_name%'")
					->count();
			$page=new \Think\Page($count,$limit);
			$show=$page->show();
			$product=M('product')
						->alias('a')
						->field('a.*,c.cat_name')
						->join("ft_cat_pro as c on a.cat_id=c.cat_id")
						->where("a.pro_name like '%$pro_name%'")
						->order('a.pro_id DESC')
						->limit($page->firstRow.','.$page->listRows)
						->select();
			
		}elseif(I('get.cat_id')){
			$cat_id=I('get.cat_id');
			$limit=6;
			$count=M('product')->where("cat_id=$cat_id")->count();
			$page=new \Think\Page($count,$limit);
			$show=$page->show();
			$product=M('product')
						->alias('a')
						->field('a.*,c.cat_name')
						->join("ft_cat_pro as c on a.cat_id=c.cat_id")
						->where("a.cat_id=$cat_id")
						->order('a.pro_id DESC')
						->limit($page->firstRow.','.$page->listRows)
						->select();
		}else{
			$limit=6;
			$count=M('product')->count();
			$page=new \Think\Page($count,$limit);
			$show=$page->show();
			$product=M('product')
						->alias('a')
						->field('a.*,c.cat_name')
						->join("ft_cat_pro as c on a.cat_id=c.cat_id")
						->order('a.pro_id DESC')
						->limit($page->firstRow.','.$page->listRows)
						->select();
		}
		$icp=M('config')->where("con_title='备案号'")->find();
        $this->assign('icp',$icp);
        $logo=M('config')->where("con_title='logo'")->find();
        $this->assign('logo',$logo);
        $banner=M('banner')->where("banner_position=2 and banner_title='产品中心'")->find();
        $this->assign('banner',$banner);
		
		
		$this->assign('show',$show);
		$this->assign('product',$product);
		$this->assign('a',$page->firstRow+1);
		
    	$this->display();
	
	}
}